package com.jing.cloud.service.chat.adapter.handler.impl;

import com.jing.cloud.service.chat.adapter.MessageBean;
import com.jing.cloud.service.chat.adapter.helper.MessageHelper;
import com.jing.cloud.service.chat.websocket.ChatHandler;
import com.jing.cloud.service.user.bean.Ticket;
import com.jing.cloud.service.user.dao.TicketDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by 29017 on 2017/9/12.
 */
@Component
public class TransferMessageHandler extends AbstractMessageHandler {

    @Autowired
    private TicketDao ticketDao;

    @Autowired
    private MessageHelper messageHelper;

    @Override
    public boolean handleMessage(MessageBean messageBean) {
        List<Long> userIds = messageHelper.getUserIds(messageBean);
        List<Ticket> tickets = ticketDao.getListByUserIds(userIds);
        for (Ticket ticket : tickets) {
            ChatHandler.pushMsg(ticket.getTicketStr(), messageBean);
        }
        return true;
    }

    @Override
    public int order() {
        return 10;
    }
}
